home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / WordPress 1.5.1.dmg / wordpress / wp-admin / options.php < prev    next >
Encoding:
PHP Script  |  2005-04-24  |  3.7 KB  |  123 lines

  1. <?php
  2. require_once('admin.php');
  3.  
  4. $title = __('Options');
  5. $this_file = 'options.php';
  6. $parent_file = 'options-general.php';
  7.  
  8. $wpvarstoreset = array('action');
  9. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  10.     $wpvar = $wpvarstoreset[$i];
  11.     if (!isset($$wpvar)) {
  12.         if (empty($_POST["$wpvar"])) {
  13.             if (empty($_GET["$wpvar"])) {
  14.                 $$wpvar = '';
  15.             } else {
  16.                 $$wpvar = $_GET["$wpvar"];
  17.             }
  18.         } else {
  19.             $$wpvar = $_POST["$wpvar"];
  20.         }
  21.     }
  22. }
  23.  
  24. if ($user_level < 6)
  25.     die ( __('Cheatin’ uh?') );
  26.  
  27. switch($action) {
  28.  
  29. case 'update':
  30.     $any_changed = 0;
  31.     
  32.     if (!$_POST['page_options']) {
  33.         foreach ($_POST as $key => $value) {
  34.             $option_names[] = "'$key'";
  35.         }
  36.         $option_names = implode(',', $option_names);
  37.     } else {
  38.         $option_names = stripslashes($_POST['page_options']);
  39.     }
  40.  
  41.     $options = $wpdb->get_results("SELECT $wpdb->options.option_id, option_name, option_type, option_value, option_admin_level FROM $wpdb->options WHERE option_name IN ($option_names)");
  42.  
  43.     // Save for later.
  44.     $old_siteurl = get_settings('siteurl');
  45.     $old_home = get_settings('home');
  46.  
  47. // HACK
  48. // Options that if not there have 0 value but need to be something like "closed"
  49.     $nonbools = array('default_ping_status', 'default_comment_status');
  50.     if ($options) {
  51.         foreach ($options as $option) {
  52.             // should we even bother checking?
  53.             if ($user_level >= $option->option_admin_level) {
  54.                 $old_val = $option->option_value;
  55.                 $new_val = trim($_POST[$option->option_name]);
  56.                 if( in_array($option->option_name, $nonbools) && ( $new_val == '0' || $new_val == '') )
  57.                     $new_val = 'closed';
  58.                 if ($new_val !== $old_val) {
  59.                     $result = $wpdb->query("UPDATE $wpdb->options SET option_value = '$new_val' WHERE option_name = '$option->option_name'");
  60.                     $any_changed++;
  61.                 }
  62.             }
  63.         }
  64.         unset($cache_settings); // so they will be re-read
  65.         get_settings('siteurl'); // make it happen now
  66.     } // end if options
  67.     
  68.     if ($any_changed) {
  69.             // If siteurl or home changed, reset cookies.
  70.             if ( get_settings('siteurl') != $old_siteurl || get_settings('home') != $old_home ) {
  71.                 // If home changed, write rewrite rules to new location.
  72.                 save_mod_rewrite_rules();
  73.                 // Get currently logged in user and password.
  74.                 get_currentuserinfo();
  75.                 // Clear cookies for old paths.
  76.                 wp_clearcookie();
  77.                 // Set cookies for new paths.
  78.                 wp_setcookie($user_login, $user_pass_md5, true, get_settings('home'), get_settings('siteurl'));
  79.             }
  80.  
  81.             //$message = sprintf(__('%d setting(s) saved... '), $any_changed);
  82.     }
  83.     
  84.         $referred = remove_query_arg('updated' , $_SERVER['HTTP_REFERER']);
  85.         $goback = add_query_arg('updated', 'true', $_SERVER['HTTP_REFERER']);
  86.         $goback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $goback);
  87.         wp_redirect($goback);
  88.     break;
  89.  
  90. default:
  91.     include('admin-header.php'); ?>
  92.  
  93. <div class="wrap">
  94.   <h2><?php _e('All options'); ?></h2>
  95.   <form name="form" action="options.php" method="post">
  96.   <input type="hidden" name="action" value="update" />
  97.   <table width="98%">
  98. <?php
  99. $options = $wpdb->get_results("SELECT * FROM $wpdb->options ORDER BY option_name");
  100.  
  101. foreach ($options as $option) :
  102.     $value = wp_specialchars($option->option_value);
  103.     echo "
  104. <tr>
  105.     <th scope='row'><label for='$option->option_name'>$option->option_name</label></th>
  106.     <td><input type='text' name='$option->option_name' id='$option->option_name' size='30' value='" . $value . "' /></td>
  107.     <td>$option->option_description</td>
  108. </tr>";
  109. endforeach;
  110. ?>
  111.   </table>
  112. <p class="submit"><input type="submit" name="Update" value="<?php _e('Update Settings »') ?>" /></p>
  113.   </form>
  114. </div>
  115.  
  116.  
  117. <?php
  118. break;
  119. } // end switch
  120.  
  121. include('admin-footer.php');
  122. ?>
  123.